package com.dly.blog.controller;

import com.dly.blog.domain.ro.ChatGptRO;
import com.dly.blog.msg.R;
import com.dly.blog.service.ChatService;
import com.dly.blog.service.GptSessionContentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/gptSessionContent")
@RequiredArgsConstructor
@Tag(name = "gpt的聊天会话模块")
@Slf4j
@Validated
public class GptSessionContentController extends BaseController{

    private final GptSessionContentService gptSessionContentService;

    @PostMapping("/save")
    @Operation(summary = "信息保存接口 保存完整的一次对话信息")
    public ResponseEntity<R<Void>> save(@RequestParam("sessionId") @NotBlank(message= "会话id不能为空") String sessionId, @RequestBody ChatGptRO chatGptRO, BindingResult br){
        validateFiled(br);
        gptSessionContentService.saveContent(sessionId, chatGptRO);
        return operate(this::success);
    }

    @Operation(summary = "获取用户使用次数")
    @GetMapping("/useNum")
    public ResponseEntity<R<Integer>> getUseNum(){
        return operate(()-> this.successDate(gptSessionContentService.getUseNum()));
    }
}
